package com.threadmethod.wait;

/**
 * @PackageName:com.threadmethod.wait
 * @ClassName:Test05
 * @Description: Interrupt()会中断线程的等待
 * @Author: zhangxiaoyu
 * @date 2021/1/11 16:41
 */
public class Test05 {

    public static void main(String[] args) throws InterruptedException {
         SubThread t = new SubThread();
         t.start();
         //睡眠2秒 确保子线程处于wait等待状态
         Thread.sleep(2000);
         t.interrupt();
    }

    private static final  Object LOCK = new Object();

    static  class SubThread extends Thread{
        @Override
        public void run() {
            synchronized (LOCK){
                System.out.println("开始等待。。。。");
                try {
                    LOCK.wait();
                } catch (InterruptedException e) {
                    System.out.println("等待被中断。。。");
                }

            }
        }
    }
}
